package com.hanggold.lambda;

import java.util.Comparator;
import java.util.stream.Stream;

class U  implements Comparator<U>{

    private String username;

    private int age;


    public U(String username, int age) {
        this.username = username;
        this.age = age;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }



    @Override
    public String toString() {
        return "U{" +
                "username='" + username + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compare(U o1, U o2) {
        return 0;
    }
}


public class SortDemo {

    public static void main(String[] args) {

        U u1 = new U("u1",12);


        U u2 = new U("u2",54);

        U u3 = new U("u3",3);

        sort((t1,t2)->{
//            return t1.getAge() > t2.getAge()?-1:(t1.getAge() == t2.getAge()?0:1);
            return t1.getAge()-t2.getAge();
        },u1,u2,u3);



    }


    public static void sort(Comparator<U> comparator,U ...u){

        Stream.of(u).sorted(comparator.reversed()).forEach(System.out::println);
    }


}
